package com.letao.server.consumer;

import com.alibaba.fastjson.JSON;
import com.letao.server.dto.RabbitMqShopInfoDTO;
import com.letao.server.utils.EsUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ShopConsumer {

    EsUtils esUtils = new EsUtils();

    @RabbitListener(queues = "shop_info")
    public void handleShopInfo(String shopInfo) {
        RabbitMqShopInfoDTO info = JSON.parseObject(shopInfo, RabbitMqShopInfoDTO.class);
        if ("insert".equals(info.getType()) || "update".equals(info.getType())) {
            esUtils.insertAndUpdateShop(info.getData());
        } else if ("delete".equals(info.getType())) {
            esUtils.deleteShop(info.getData());
        }
    }

}
